import React, { ReactElement, ReactNode } from "react";
import { useSelector } from "react-redux";
import { RootState } from "@/store";

interface ButtonCheckProps {
  roles: string[];
  children: ReactElement;
}
const ButtonCheck = ({ roles, children }: ButtonCheckProps) => {
  // 取出当前用户的角色
  const role = useSelector((state: RootState) => state.user.role) + "";
  if (roles.includes(role)) {
    return children;
  } else {
    return {
      ...children,
      props: {
        ...children.props,
        disabled: true,
      },
    };
    // return React.createElement(Children, {
    //   disabled: true,
    // });
    // @ts-ignore
    // return <Children id="box" />;
  }
};

export default ButtonCheck;
